package edu.gdin.ecommerce.dao;

import org.springframework.stereotype.Repository;

import edu.gdin.ecommerce.model.OperLog;
import edu.gdin.ecommerce.util.Pager;

@Repository("operLogDAO")
public class OperLogDAO extends BaseDAO {

	
	public Pager query(OperLog log, String operTime1, String operTime2, int currentPage) {
		
		StringBuffer hql = new StringBuffer();
		hql.append("from OperLog o where 1=1 ");
		
		if(log != null) {
			if (log.getType() != null && !log.getType().equals("-1")) {
				hql.append(" and o.type = '" + log.getType() + "'");
			}
			if (log.getResult() != null && !log.getResult().equals("-1")) {
				hql.append(" and o.result = '" + log.getResult() + "'");
			}
			if (log.getAccount() != null && !log.getAccount().equals("")) {
				hql.append(" and o.account like '%" + log.getAccount() + "%'");
			}
			if (log.getOperIp() != null && !log.getOperIp().equals("")) {
				hql.append(" and o.operIp like '%" + log.getOperIp() + "%'");
			}
			if (log.getAttachNo() != null && !log.getAttachNo().equals("")) {
				hql.append(" and o.attachNo like '%" + log.getAttachNo() + "%'");
			}
			if (log.getOperDesc() != null && !log.getOperDesc().equals("")) {
				hql.append(" and o.operDesc like '%" + log.getOperDesc() + "%'");
			}
		}
		
		if(operTime1 != null && !operTime1.equals("")) {
			hql.append(" and o.operTime >= '" + operTime1 + " 00:00:00'");
		}
		if(operTime2 != null && !operTime2.equals("")) {
			hql.append(" and o.operTime <= '" + operTime2 + " 23:59:59'");
		}
		hql.append(" order by o.operTime desc");
		
		return this.getPage(hql.toString(), currentPage);
		
	}
}
